package comp.wxapi.bean;

import org.apache.commons.lang3.StringUtils;

import weixin.popular.util.SignatureUtil;

public class BaseConfigBean extends WxEventParamBean {
	
	private static final long serialVersionUID = 8068719135181102301L;
	/**微信/小程序/开放平台appid*/
	private String appid;
	/**微信/小程序/开放平台appsecret*/
	private String appsecret;
	/**微信推送消息加解密token*/
	private String token;
	/**微信推送消息加解密秘钥*/
	private String encodingAESKey;
	/**微信推送消息通知地址*/
	private String notifyUrl;
	/**用户OpenID*/
	private String openid;
	/**微信小程序用户sessioKey*/
	private String sessionKey;
//	/**商户号*/
//	private String mchId;
//	/**商户秘钥*/
//	private String mchKey;
//	/**商户支付证书地址*/
//	private String apiClientCertPath;
	/**支付通知地址*/
	private String payNotifyUrl;
	/**退款成功通知地址*/
	private String refundNotifyUrl;
	
	public String getPayNotifyUrl() {
		return payNotifyUrl;
	}

	public void setPayNotifyUrl(String payNotifyUrl) {
		this.payNotifyUrl = payNotifyUrl;
	}

	public String getRefundNotifyUrl() {
		return refundNotifyUrl;
	}

	public void setRefundNotifyUrl(String refundNotifyUrl) {
		this.refundNotifyUrl = refundNotifyUrl;
	}

	public String getSessionKey() {
		return sessionKey;
	}

	public void setSessionKey(String sessionKey) {
		this.sessionKey = sessionKey;
	}

	public String getOpenid() {
		return openid;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}

	public String getNotifyUrl() {
		return notifyUrl;
	}

	public void setNotifyUrl(String notifyUrl) {
		this.notifyUrl = notifyUrl;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getEncodingAESKey() {
		return encodingAESKey;
	}

	public void setEncodingAESKey(String encodingAESKey) {
		this.encodingAESKey = encodingAESKey;
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getAppsecret() {
		return appsecret;
	}

	public void setAppsecret(String appsecret) {
		this.appsecret = appsecret;
	}
	
	public boolean isAes() {
		
		if(StringUtils.isNotEmpty(this.getEncrypt_type()) && "aes".equals(this.getEncrypt_type())) {
			
			return true;
		}
		return false;
	}
	
	public boolean isWxOffical() {
		boolean flag = StringUtils.isNotEmpty(this.getSignature()) && StringUtils.isNotEmpty(this.getToken())
				&& StringUtils.isNotEmpty(this.getTimestamp()) && StringUtils.isNotEmpty(this.getNonce());
		if(flag) {
			if(this.getSignature().equals(SignatureUtil.generateEventMessageSignature(this.getToken(),this.getTimestamp(), this.getNonce())))
				return true;
		}
		return false;
	}
}
